﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
using System.Threading;

namespace 关键字搜索
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        public class pp : Form1
        {
            public void PRINT()
            {

                try
                {
                    WebRequest qing= WebRequest.Create("https://baike.baidu.com/item/" + textBox3.Text);
                    WebResponse response = qing.GetResponse();
                    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    string temp = reader.ReadToEnd();
                    string x = @"[\u4E00-\u9FFF]+";
                    MatchCollection Matches = Regex.Matches
                    (temp, x, RegexOptions.IgnoreCase);
                    StringBuilder sb = new StringBuilder();
                    foreach (Match NextMatch in Matches)
                    {
                        sb.Append(NextMatch.Value);
                    }
                    textBox1.Text = sb.ToString().Substring(0, 200);

                    reader.Close();
                    reader.Dispose();
                    response.Close();
                }
                catch (Exception ex)
                {
                    textBox1.Text = ex.Message;
                }
            }
        }
            private void PRINT()
            {
                try
                {
                    WebRequest qing = WebRequest.Create("https://baike.baidu.com/item/" + textBox3.Text);
                    WebResponse response = qing.GetResponse();
                    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    string temp = reader.ReadToEnd();
                    string x = @"[\u4E00-\u9FFF]+";
                    MatchCollection Matches = Regex.Matches
                    (temp, x, RegexOptions.IgnoreCase);
                    StringBuilder sb = new StringBuilder();
                    foreach (Match NextMatch in Matches)
                    {
                        sb.Append(NextMatch.Value);
                    }
                    textBox1.Text = sb.ToString().Substring(0, 200);

                    reader.Close();
                    reader.Dispose();
                    response.Close();
                }
                catch (Exception ex)
                {
                    textBox1.Text = ex.Message;
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {


                try
                {
                    WebRequest qing = WebRequest.Create("https://baike.baidu.com/item/" + textBox3.Text);
                    WebResponse response = qing.GetResponse();
                    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    string t = reader.ReadToEnd();
                    string x = @"[\u4E00-\u9FFF]+";
                    MatchCollection Matches = Regex.Matches
                    (t, x, RegexOptions.IgnoreCase);
                    StringBuilder sb = new StringBuilder();
                    foreach (Match NextMatch in Matches)
                    {
                        sb.Append(NextMatch.Value);
                    }
                    textBox2.Text = sb.ToString().Substring(0, 200);

                    reader.Close();
                    reader.Dispose();
                    response.Close();
                }
                catch (Exception ex)
                {
                    textBox2.Text = ex.Message;
                }

                pp mm = new pp();
                Thread another = new Thread(mm.PRINT);
                another.Start();
                PRINT();

            }




        }

    }



